#!/bin/sh
echo $0 $*

GAMEDIR=${PWD}
echo ==========GAMEDIR is $GAMEDIR
controlfolder="../PortMaster"

source $controlfolder/control.txt
#source $controlfolder/tasksetter

get_controls

# Enable logging
> "$GAMEDIR/log.txt" && exec > >(tee "$GAMEDIR/log.txt") 2>&1

CONFDIR="$GAMEDIR/conf/"
RUNTIME_DIR="$controlfolder/libs"
# Ensure the conf directory exists
mkdir -p "$GAMEDIR/conf"

# Set the XDG environment variables for config & savefiles
export XDG_CONFIG_HOME="$CONFDIR"
export XDG_DATA_HOME="$CONFDIR"
cd "$GAMEDIR"


# runtime="godot_3.5.2"
# $ESUDO $controlfolder/harbourmaster --quiet --no-check runtime_check "$runtime"
GODOT_BINARY="frt_aarch64_3.5.2"
GODOT_OPTS="--resolution 1280x720 -f"
GODOT_RUN="$ESUDO $RUNTIME_DIR/$GODOT_BINARY $GODOT_OPTS"


$GPTOKEYB $GODOT_BINARY -c "hyperfight.gptk" &
$GODOT_RUN --main-pack "hyperfight.pck" 


$ESUDO kill -9 $(pidof gptokeyb)
$ESUDO systemctl restart oga_events &
printf "\033c" > /dev/tty0